package secondBrush.list;

public class E01Leetcode203 {
    public static ListNode removeElements(ListNode head, int val) {
        ListNode cur = new ListNode(-1,head);
        ListNode dow = cur;


        while (dow.next != null) {
            if (dow.next.val == val) {
                dow.next = dow.next.next;

            }else {
                dow = dow.next;

            }

        }
        return cur.next;

    }

    public static void main(String[] args) {
        ListNode head = new ListNode(7,new ListNode(7,new ListNode(7,new ListNode(7,new ListNode(7,new ListNode(7,new ListNode(7,null)))))));
        System.out.println(removeElements(head, 7));

    }


    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
